// ----------------------------------
// RSDK Project: Sonic 1 Forever X Doki Doki Literature Club
// Script Description: Sidebar
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 1 : TYPE_SEGA
private alias 75 : SPACING_VALUE

private alias object.value0 : object.timer
private alias object.value1 : object.xPosition
private alias object.value2 : object.circleY
private alias object.value3 : object.speedPercent
private alias object.value7 : object.optionsXoffset

// Function declarations


event ObjectMain
	switch object.state
	case 0
		object.ixpos = 120
		object.circleY = -100	
		object.optionsXoffset = 0	
		object.state++
		break

	case 1
		temp0 = 10
		if object.ixpos > 0
			temp1 = temp0
			temp1 -= object.ixpos
			temp1 >>= 4
			temp1--
			object.ixpos += temp1
		else
			object.ixpos = 0
			object.state++
		end if
		break

	case 2
		object.yvel += 0x4000
		object.speedPercent += object.yvel
		temp0 = object.speedPercent
		temp0 >>= 16
		object.circleY += temp0
		object.speedPercent &= 0xFFFF

		if object.yvel > 0
			if object.circleY >= 20
				object.yvel >>= 1
				temp0 = object.yvel
				temp0 >>= 2
				object.yvel += temp0
				object.timer++
				if object.timer < 10
					FlipSign(object.yvel)
					if object.value4 == 0
						object.value4 = 1
					end if
				else
					object.timer = 0
					object.yvel = 0
					object.speedPercent = 0
					object.circleY = 20
					object.state++
				end if
			end if
		end if
		break
	case 3
		temp0 = 10
		if object.ixpos > 0
			temp1 = temp0
			temp1 -= object.ixpos
			temp1 >>= 4
			temp1--
			object.ixpos += temp1
		else
			object.ixpos = 0
		end if
		break
	end switch

	if object[OPTIONS_SLOT].type == TypeName[Options]
		object.value4 = 2
		object.state = 3
		object.circleY = 20

		temp0 = 10
		if object.ixpos > 0
			temp1 = temp0
			temp1 -= object.ixpos
			temp1 >>= 4
			temp1--
			object.ixpos += temp1
		else
			object.ixpos = 0
		end if	
		if screen.xsize == 320
			if object.optionsXoffset > -132
				temp1 = 4
				temp1 -= object.optionsXoffset
				temp1 >>= 3
				temp1++
				object.optionsXoffset -= temp1
			else
				object.optionsXoffset = -132
			end if	
		else
			object.optionsXoffset = 0	
		end if				
	else
		if screen.xsize == 320
			if object.optionsXoffset < 0
				temp1 = 4
				temp1 -= object.optionsXoffset
				temp1 >>= 3
				temp1++
				object.optionsXoffset += temp1
			else
				object.optionsXoffset = 0
			end if				
		else
			object.optionsXoffset = 0		
		end if			
	end if

	if object.value4 == 1
		object.value5 = 200

		temp0 = 0
		temp2 = 80
		temp3 = object.circleY
		while temp0 < 20
			Rand(temp1, 2)
			CreateTempObject(TypeName[Sparkles], temp1, 0, 0)
			object[tempObjectPos].ixpos = temp2
			object[tempObjectPos].iypos = temp3
			object[tempObjectPos].priority = PRIORITY_ACTIVE
			object[tempObjectPos].drawOrder = 6
			Rand(temp1, 4)
			Rand(temp4, 4)
			Rand(temp5, 1)
			Rand(temp6, 1)
			temp5++
			temp6++
			temp1 += temp4
			temp1 /= temp6
			temp1 *= temp5

			object[tempObjectPos].speed = temp1
			temp5 = temp1
			object[tempObjectPos].value1 = temp3
			if temp1 == 2
				object[tempObjectPos].value1 -= temp4
			else	
				object[tempObjectPos].value1 += temp4
			end if	
			object[tempObjectPos].alpha = 256
			temp3 += 2
			temp0++
		loop

		object.value4++
	else
		object.value5 -= 6
		if object.value5 < 0
			object.value5 = 0
		end if
	end if
end event


event ObjectDraw
	temp0 = object.ixpos
	temp0 -= object.optionsXoffset
	FlipSign(temp0)
	DrawSpriteScreenXY(0, temp0, 0)	
	object.alpha = 180
	object.inkEffect = INK_ALPHA
	SetActivePalette(3, 0, 256)
	DrawSpriteScreenFX(0, FX_INK, temp0, 0)
	SetActivePalette(0, 0, 256)	
	DrawSpriteScreenXY(2, temp0, 0)		
	if screen.xsize > 320
		CheckNotEqual(object[OPTIONS_SLOT].type, TypeName[Options])
		temp0 = checkResult
		CheckLower(object.state, 3)
		temp0 |= checkResult
	else
		temp0 = 1
	end if	
	if temp0 == 1
		temp1 = 29
		temp1 += object.optionsXoffset		
		DrawSpriteScreenXY(1, temp1, object.circleY)
		object.alpha = 180
		object.inkEffect = INK_ALPHA
		SetActivePalette(3, 0, 256)
		DrawSpriteScreenFX(1, FX_INK, temp1, object.circleY)
		SetActivePalette(0, 0, 256)	
		DrawSpriteScreenXY(3, temp1, object.circleY)		
		DrawSpriteScreenXY(5, temp1, object.circleY)		
		DrawSpriteScreenXY(4, temp1, object.circleY)		
	end if
	object.alpha = object.value5
	object.inkEffect = INK_ALPHA
	DrawRect(0, 0, screen.xsize, screen.ysize, color7, color7, color7, object.alpha)
end event


event ObjectStartup
	LoadSpriteSheet("DDLCMenu/Menu.gif")
	SpriteFrame(0, 0, 131, 240, 1, 1) // 0 - Sidebar
	SpriteFrame(0, -15, 102, 102, 286, 533) // 1 - Circle
	SpriteFrame(0, 0, 131, 240, 484, 1) // 2 - Sidebar curve part
	SpriteFrame(0, -15, 102, 102, 15, 503) // 3 - color circle part
	SpriteFrame(0, -17, 103, 96, 514, 484) // 4 - Logo
	SpriteFrame(8, 3, 86, 78, 549, 405) // 5 - Hearts
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
